package br.com.gip.repository.dao;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;


import br.com.gip.repository.model.Categoria;

import br.com.gip.repository.persistence.HibernateDao;

@Repository
@Transactional
public class CategoriaDao extends HibernateDao<Categoria, Long> {

	private static final long serialVersionUID = 5095491169508524376L;
	
	
	@SuppressWarnings("unchecked")
	public List<Categoria> findByFilter(String nome) {
		Criteria criteria = this.getCurrentSession().createCriteria(Categoria.class, "a");
		
		if (!StringUtils.isBlank(nome)) {
			criteria.add(Restrictions.eq("nome", nome));	
		}
		
			
		return (List<Categoria>) criteria.list();
	}

}